home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / intuisup.lha / Intuisup / source.lha / Pointer / pointer.c < prev    next >
C/C++ Source or Header  |  1992-07-19  |  7KB  |  245 lines

  1. /* $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1992 by Torsten Jürgeleit
  4.  *
  5.  *    Name .....: pointer.c
  6.  *    Created ..: Wednesday 08-Jan-92 22:34:41
  7.  *    Revision .: 2
  8.  *
  9.  *    Date        Author                 Comment
  10.  *    =========   ====================   ====================
  11.  *    11-Jul-92   Torsten Jürgeleit      now visible gadgets can be removed
  12.  *                       by changing mouse pointer to
  13.  *                       busy pointer
  14.  *    13-Apr-92   Torsten Jürgeleit      remove menu for busy pointer
  15.  *    08-Jan-92   Torsten Jürgeleit      Created this file!
  16.  *
  17.  ****************************************************************************
  18.  *
  19.  *    Support routines for mouse pointer
  20.  *
  21.  * $Revision Header ********************************************************/
  22.  
  23.     /* Includes */
  24.  
  25. #include <exec/types.h>
  26. #include <exec/memory.h>
  27. #include <devices/input.h>
  28. #include <devices/inputevent.h>
  29. #include <intuition/intuition.h>
  30. #include <intuition/screens.h>
  31. #ifdef AZTEC_C
  32. #include <functions.h>   /* needed for Aztec C - prototypes and pragmas for all Amiga system functions */
  33. #endif
  34. #include <libraries/memwatch.h>   /* header file for memory debug link library (Fish 240) - AFTER functions.h */
  35. #include "/render/render.h"
  36. #include "/gadgets/gadgets.h"   /* needed for "/gadgets/imports.h" */
  37. #include "/gadgets/imports.h"   /* protos for remove/display_visible_gadget_lists() */
  38. #include "pointer.h"
  39.  
  40.     /* Defines for for workbench busy ballon */
  41.  
  42. #define BUSY_POINTER_WIDTH    15
  43. #define BUSY_POINTER_HEIGHT    22
  44. #define BUSY_POINTER_XOFFSET    -7
  45. #define BUSY_POINTER_YOFFSET    -8
  46.  
  47.     /* Statics for for workbench busy ballon */
  48.  
  49. STATIC UWORD busy_pointer_image[] = {
  50.     0x0000, 0x0000,
  51.  
  52.     0x0600, 0x0600,
  53.     0x0f40, 0x0f40,
  54.     0x3fe0, 0x3fe0,
  55.     0x7fe0, 0x7fe0,
  56.     0x61f0, 0x7ff0,
  57.     0x7bf8, 0x7ff8,
  58.     0xf7f8, 0xfff8,
  59.     0x61fc, 0x7ffc,
  60.     0x7f0c, 0x7ffc,
  61.     0x3fde, 0x3ffe,
  62.     0x7fbc, 0x7ffc,
  63.     0x3f0c, 0x3ffc,
  64.     0x1ff8, 0x1ff8,
  65.     0x07f0, 0x07f0,
  66.     0x01c0, 0x01c0,
  67.     0x0700, 0x0700,
  68.     0x0fc0, 0x0fc0,
  69.     0x0680, 0x0680,
  70.     0x0000, 0x0000,
  71.     0x00c0, 0x00c0,
  72.     0x00e0, 0x00e0,
  73.     0x0040, 0x0040,
  74.  
  75.     0x0000, 0x0000
  76. };
  77. STATIC struct PointerData  busy_pointer_data = {
  78.     BUSY_POINTER_WIDTH,
  79.     BUSY_POINTER_HEIGHT,
  80.     BUSY_POINTER_XOFFSET,
  81.     BUSY_POINTER_YOFFSET,
  82.     &busy_pointer_image[0]
  83. };
  84.     /* Change mouse pointer for given window - save old one in singly linked list */
  85.  
  86.    VOID
  87. change_mouse_pointer(struct Window  *win, struct PointerData  *pd,
  88.                                 BOOL remove_gadgets)
  89. {
  90.    if (win) {
  91.       struct PointerList  *pl;
  92.  
  93.       if (pl = AllocMem((LONG)sizeof(struct PointerList),
  94.                       (LONG)MEMF_PUBLIC | MEMF_CLEAR)) {
  95.      struct Menu  *menu = NULL;
  96.  
  97.      /* List for visible gadget lists MUST be initialized */
  98.      NewList((struct List *)&pl->pl_GadgetList);
  99.  
  100.      /* If no pointer data given then use busy pointer */
  101.      if (!pd) {
  102.         pd = &busy_pointer_data;
  103.  
  104.         /* Remove menu for busy pointer */
  105.         if (menu = win->MenuStrip) {
  106.            ClearMenuStrip(win);
  107.         }
  108.  
  109.         /* Remove visible gadget lists too if requested */
  110.         if (remove_gadgets == TRUE) {
  111.            remove_visible_gadget_lists(win, &pl->pl_GadgetList);
  112.         }
  113.      }
  114.  
  115.      /* Allocate chipmem buffer for pointer data if necessary */
  116.      if (!(TypeOfMem((BYTE *)pd->pd_Data) & MEMF_CHIP) &&
  117.          !(pl->pl_Buffer = AllocMem(pl->pl_BufferSize = (pd->pd_Height +
  118.                   2) * 4, (LONG)MEMF_PUBLIC | MEMF_CHIP))) {
  119.         FreeMem(pl, (LONG)sizeof(struct PointerList));
  120.      } else {
  121.         UWORD *data;
  122.  
  123.         /* Init pointer list */
  124.         pl->pl_ID   = ISUP_ID;
  125.         pl->pl_Menu = menu;
  126.         if (!pl->pl_Buffer) {
  127.            data = pd->pd_Data;
  128.         } else {
  129.            data = pl->pl_Buffer;
  130.            CopyMem((BYTE *)pd->pd_Data, (BYTE *)data, pl->pl_BufferSize);
  131.         }
  132.  
  133.         /* Save old pointer data in pointer list */
  134.         Forbid();
  135.         pl->pl_Width   = win->PtrWidth;
  136.         pl->pl_Height  = win->PtrHeight;
  137.         pl->pl_XOffset = win->XOffset;
  138.         pl->pl_YOffset = win->YOffset;
  139.         pl->pl_Data    = win->Pointer;
  140.  
  141.         /* Append old window user data ptr and set new one */
  142.         pl->pl_Next   = (struct PointerList *)win->UserData;
  143.         win->UserData = (BYTE *)pl;
  144.         Permit();
  145.  
  146.         /* Install new pointer image */
  147.         SetPointer(win, data, (LONG)pd->pd_Height, (LONG)pd->pd_Width,
  148.                 (LONG)pd->pd_XOffset, (LONG)pd->pd_YOffset);
  149.      }
  150.       }
  151.    }
  152. }
  153.     /* Restore saved mouse pointer for given window - use first entry from singly linked list */
  154.  
  155.    VOID
  156. restore_mouse_pointer(struct Window  *win)
  157. {
  158.    if (win) {
  159.       struct PointerList  *pl;
  160.  
  161.       /* Get saved pointer - if no data given then use default one */
  162.       if ((pl = (struct PointerList *)win->UserData) &&
  163.                              pl->pl_ID == ISUP_ID) {
  164.      struct Menu  *menu;
  165.  
  166.      /* Remove first pointer from list */
  167.      win->UserData = (BYTE *)pl->pl_Next;
  168.  
  169.      /* Restore menu - if any */
  170.      if (menu = pl->pl_Menu) {
  171.         SetMenuStrip(win, menu);
  172.      }
  173.  
  174.      /* Display visible gadgets */
  175.      display_visible_gadget_lists(win, &pl->pl_GadgetList);
  176.  
  177.      /* Restore pointer image and free pointer data */
  178.      SetPointer(win, pl->pl_Data, (LONG)pl->pl_Height,
  179.         (LONG)pl->pl_Width, (LONG)pl->pl_XOffset, (LONG)pl->pl_YOffset);
  180.      if (pl->pl_Buffer) {
  181.         FreeMem(pl->pl_Buffer, pl->pl_BufferSize);
  182.      }
  183.      FreeMem(pl, (LONG)sizeof(struct PointerList));
  184.       } else {
  185.      ClearPointer(win);
  186.       }
  187.    }
  188. }
  189.     /* Move mouse pointer to given position relativ to specified window */
  190.  
  191.    VOID
  192. move_mouse_pointer(struct Window  *win, SHORT x, SHORT y, BOOL button)
  193. {
  194.    struct MsgPort     *port;
  195.    struct IOStdReq    *ior;
  196.    struct InputEvent  *ie;
  197.  
  198.    if (win && (port = CreatePort((BYTE *)NULL, 0L))) {
  199.       if (ior = CreateStdIO(port)) {
  200.      if (!OpenDevice("input.device", 0L, (struct IORequest *)ior, 0L)) {
  201.         if (ie = AllocMem((LONG)sizeof(struct InputEvent),
  202.                       (LONG)MEMF_PUBLIC | MEMF_CLEAR)) {
  203.            struct Screen  *screen = win->WScreen;
  204.  
  205.            /* Init IO request */
  206.            ior->io_Command = IND_WRITEEVENT;
  207.            ior->io_Flags   = 0;
  208.            ior->io_Data    = (APTR)ie;
  209.            ior->io_Length  = sizeof(struct InputEvent);
  210.  
  211.            /* Convert mouse position */
  212.            x += win->LeftEdge;
  213.            y += win->TopEdge;
  214.            if (!(screen->ViewPort.Modes & HIRES)) {
  215.           x *= 2;
  216.            }
  217.            if (!(screen->ViewPort.Modes & LACE)) {
  218.           y *= 2;
  219.            }
  220.            y += 2 * screen->TopEdge;
  221.  
  222.            /* Init input event */
  223.            ie->ie_Class = IECLASS_POINTERPOS;
  224.            ie->ie_X     = x;
  225.            ie->ie_Y     = y;
  226.  
  227.            /* Send IO request - if button then first button down and then up event */
  228.            if (button) {
  229.           ie->ie_Code = IECODE_LBUTTON;
  230.           DoIO((struct IORequest *)ior);
  231.           ie->ie_Code = IECODE_LBUTTON | IECODE_UP_PREFIX;
  232.            } else {
  233.           ie->ie_Code = IECODE_NOBUTTON;
  234.            }
  235.            DoIO((struct IORequest *)ior);
  236.            FreeMem(ie, (LONG)sizeof(struct InputEvent));
  237.         }
  238.         CloseDevice((struct IORequest *)ior);
  239.      }
  240.      DeleteStdIO(ior);
  241.       }
  242.       DeletePort(port);
  243.    }
  244. }
  245.